package com.seecen.interceptors;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.seecen.utils.JwtHelper;
import com.seecen.utils.Result;
import com.seecen.utils.ResultCodeEnum;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;


@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private JwtHelper jwtHelper;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {

//        String token = request.getHeader("token");
//        boolean isExpiration = jwtHelper.isExpiration(token);
//        if(!isExpiration) return true;
//        Result ret = Result.build(null, ResultCodeEnum.NOTLOGIN);
//
//        //jackson --- 原始方法
//        ObjectMapper mapper = new ObjectMapper();
//        String json = mapper.writeValueAsString(ret);
//
//        response.getWriter().print(json);
//        return false;

        return true;
    }
}
